package com.du.cloud.service.oauth.service;

import cn.hutool.core.util.StrUtil;
import com.du.cloud.security.service.TokenUser;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.oauth2.common.exceptions.InvalidGrantException;
import org.springframework.stereotype.Service;

/**
 * Desc:
 * Author: dushuang
 * Date: 2020/5/29
 **/
@Service
public class CustomUserDetailsService {
    public TokenUser loadUserByPhoneAndPassword(String phone, String password) {
        if (StrUtil.isEmpty(phone) || StrUtil.isEmpty(password)) {
            throw new InvalidGrantException("您输入的手机号或密码不正确");
        }
        // 判断成功后返回用户细节
        return new TokenUser(
                1,
                phone,
                "Phone&Password",
                "666",
                true,
                AuthorityUtils.commaSeparatedStringToAuthorityList("admin,user,root")
        );
    }

    public TokenUser loadUserByPhoneAndSmsCode(String phone, String smscode) {
        if (StrUtil.isEmpty(phone) || StrUtil.isEmpty(smscode)) {
            throw new InvalidGrantException("您输入的手机号或短信验证码不正确");
        }
        // 判断成功后返回用户细节
        return new TokenUser(
                1,
                phone,
                "Phone&SmsCode",
                "888",
                true,
                AuthorityUtils.commaSeparatedStringToAuthorityList("admin,user,root")
        );
    }

}
